package com.my.reject;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Test001 {


    public static void main(String[] args){
        try {
            Class cl=Class.forName(Employee.class.getName());
            Field[] fields=cl.getDeclaredFields();
            for (int i = 0; i < fields.length; i++) {
                System.out.println("field:"+fields[i].getName());
            }

            Method[] methods=cl.getDeclaredMethods();
            for (int i = 0; i < methods.length; i++) {
                System.out.println("Method:"+methods[i].getName());
            }

//
           Employee employee= (Employee) cl.newInstance();
           Field field=cl.getDeclaredField("str") ;
           field.setAccessible(true);
           field.set(employee,"你好");
            employee.sayStr();

            Method method=cl.getDeclaredMethod("sayHello");
            method.setAccessible(true);
            method.invoke(employee);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
